from django.db import models
from django.contrib.auth.models import User, UserManager

class Team(models.Model):
    team = models.CharField(max_length = '40') # country
    
    def __unicode__(self):
        return self.team

class Game(models.Model):
    home_team = models.ForeignKey('Team', related_name = 'first_team', blank=True, null=True)
    guest_team = models.ForeignKey('Team', related_name = 'second_team', blank=True, null=True)
    date = models.DateTimeField()
    is_completed = models.BooleanField()
    is_playoff = models.BooleanField()
    is_locked = models.BooleanField()
    playoff_label = models.CharField(max_length = '40', blank=True, null=True)
    home_team_score = models.IntegerField(blank=True, null=True)
    guest_team_score = models.IntegerField(blank=True, null=True)
    yellow_cards = models.IntegerField(blank=True, null=True)
    red_cards = models.IntegerField(blank=True, null=True)
    
    def __unicode__(self):
        return u'%s-%s(%s)' % (self.home_team, self.guest_team, self.date)
    
class Prediction(models.Model):
    game = models.ForeignKey(Game)
    user = models.ForeignKey(User)
    home_team_bet = models.IntegerField(blank=True, null=True)
    guest_team_bet = models.IntegerField(blank=True, null=True)
    is_playoff = models.BooleanField()
    predicted_home_team = models.ForeignKey(Team, related_name='predicted_home_team', blank=True, null=True)
    predicted_guest_team = models.ForeignKey(Team, related_name='predicted_guest_team', blank=True, null=True)
    
    def __unicode__(self):
        return u'%s-%s' % (self.user, self.game)
    
class UserProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    predicted_yellow_cards = models.IntegerField(blank=True, null=True)
    predicted_red_cards = models.IntegerField(blank=True, null=True)
    objects = UserManager()
    
    def __unicode__(self):
        return self.user
    
class Settings(models.Model):
    bank_total = models.IntegerField(blank=True, null=True)